<template>
	<div class="main">
		<el-button type="danger" @click="getShareServer()">获取分享服务</el-button>
		<el-button type="danger" @click="sendShare()">分享</el-button>
		v1.4
	</div>
</template>
<script>
export default {
	data () {
		return {
			shares:'',
		}
	},
	methods:{
		// 分享
		sendShare:function(){
			// 判断是否授权
			if (this.shares.authenticated) {
				var msg = {
					href: 'http://www.baidu.com',
					title: '标题',
					content: '描述',
					thumbs: ['http://tuxiaozhu.oss-cn-shenzhen.aliyuncs.com/6433aa70b97c485f91f6287f9e16317a.png'],
					extra: {
						scene: 'WXSceneSession', // 好友：WXSceneSession，朋友圈：WXSceneTimeline
					}
				};
				this.shares.send(msg, function() {
					alert("分享成功!");
				}, function(e) {
					alert("分享失败!");
				});
			} 
			else {
				alert("---未授权---");
			}
		},
		// 获取分享服务
		getShareServer:function(){
			plus.share.getServices(s=> {
				s.map(o=>{
					// 寻找微信
					if(o.id == 'weixin'){
						this.shares = o;
					}
				})
			},error=>{
				plus.nativeUI.toast('获取失败');
			});
		}
	},
	mounted(){
		
	},
	created(){

	}
}
</script>
<style lang="scss" scoped>
@import '@/style/base/border.scss';
	.main{
		margin: 20px;
	}
</style>
